package com.hctforgreen.greenservice.model;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.hctforgreen.greenservice.model.AllExamListEntity.ExamEntity;
import com.hctforgreen.greenservice.utils.HctConstants;

/**
 * 6.9、获取试题类型接口
 * @author Tallen Zhai
 *
 */
public class RepTypeListEntity extends BaseEntity {
	private static final long serialVersionUID = -6536034442973890736L;

	public List<RepTypeEntity> dataList = null;
	
	public String state = "";
	
	public final static String STATE = "state";
	private final static String BODY = "body";
	
	public static RepTypeListEntity parse(JSONObject jsonObject)throws JSONException{
		RepTypeListEntity bean = new RepTypeListEntity();
		if(jsonObject.has(STATE)){
			bean.state = jsonObject.getString(STATE);
		}
		/**
		 * 解析body节点
		 */
		if (jsonObject.has(BODY)) {
			
			JSONArray jsonArray = jsonObject.getJSONArray(BODY);
				
			bean.dataList = new ArrayList<RepTypeEntity>();
			for (int i = 0; i < jsonArray.length(); i++) {
				JSONObject object = jsonArray.getJSONObject(i);
				RepTypeEntity entity = RepTypeEntity.parse(object);
				bean.dataList.add(entity);
			}
			
		}
		/**
		 * -1表示:无数据
		 */
		if(bean.state.equals(HctConstants.RESULT_STATE_FAILD)
				&& bean.dataList == null){
			bean.dataList = new ArrayList<RepTypeEntity>();
		}
		return bean;
	}
	/**
	 * 试题类型
	 * @author Tallen Zhai
	 *
	 */
	public static class RepTypeEntity extends BaseEntity {

		private static final long serialVersionUID = 7260147593619791665L;
		public String id = "";
		public String typeName = "";
		//============只在页面中用到==============
		public int count = 0;
		public List<ExamEntity> dataLst = new ArrayList<ExamEntity>();
		public boolean isChecked = false;
		public final static String ID = "id";
		public final static String TYPE_NAME = "typeName";
		
		public static RepTypeEntity parse(JSONObject jsonObject)
				throws JSONException {
			RepTypeEntity bean = new RepTypeEntity();
			if (jsonObject.has(ID)) {
				bean.id = jsonObject.getString(ID);
			}
			if (jsonObject.has(TYPE_NAME)) {
				bean.typeName = jsonObject.getString(TYPE_NAME);
			}
			return bean;
		}
	}
}
